package com.job.ZhangMeng.Homework0714;

/**
 * 2022.07.14  clone
 * 张孟
 */

public class Beauty implements Cloneable{
    private String beautyName;
    private Cat cat;

    public Beauty(){}
    public Beauty(String bN,Cat cat){
        this.beautyName=bN;
        this.cat=cat;
    }

    public String getBeautyName() {
        return beautyName;
    }

    public void setBeautyName(String beautyName) {
        this.beautyName = beautyName;
    }

    public Cat getCat() {
        return cat;
    }

    public void setCat(Cat cat) {
        this.cat = cat;
    }

    public static void main(String[] args) throws CloneNotSupportedException {  //抛出异常
        Cat cat=new Cat("Tom");
        Beauty beauty=new Beauty("Jerry", cat);

        Beauty clone=(Beauty)beauty.clone();    //clone()方法返回Object类的对象,
                                                //因此需要强制类型转换,下溯造型为Beauty类的对象
        System.out.println(beauty==clone);  //false,地址不同
        System.out.println(beauty.getCat()==clone.getCat());    //true,cat相同
    }
}
